1 #include<iostream>
2 #include<stdio.h>
3 #include<conio.h>
4 #include<process.h>
5 #include<fstream>
6 #include<
string>
7 #include<stdlib.h>

8 using
namespace std;
9 class
product
10 {
11     
int prno;
12     
char name[50];
13     
float price,qty,dis,tax;
14 public
:
15     
void createpr()
16     {
17         cout<<endl<<
"Enter the product number"<<endl;
18         cin>>prno;
19         cout<<
"Enter the product name"<<endl;
20         std::cin>>name;
21         cout<<
"Enter the price of the product"<<endl;
22         cin>>price;
23         cout<<
"Enter the discount percentage"<<endl;
24         cin>>dis;
25     }
26     
void showpr()
27     {
28
29         cout<<
"Product number: "<<prno<<endl;
30         cout<<
"Product name: "<<std::cout<<name<<endl;
31         cout<<
"Product price: "<<price<<endl;
32         cout<<
"Discount percentage: "<<dis<<endl;
33     }
34     
int retprno()
35     {
36         
return prno;
37     }
38     
float retprice()
39     {
40         
return price;
41     }
42     
char* retname()
43     {
44         
return name;
45     }
46     
int retdis()
47     {
48         
return dis;
49     }
50 };
51 fstream fp;
52 product pr;

53 int
writepr()
54 {
55     fp.open(
"SMBS.dat",ios::out|ios::app);
56     pr.createpr();
57     fp.write((
char*)&pr,sizeof(product));
58     fp.close();
59     
return 0;
60
61 }

62 int
disp()
63 {
64     cout<<
"Display all the records: "<<endl;
65     fp.open(
"SMBS.dat",ios::in|ios::out);
66     
while(fp.read((char*)&pr,sizeof(product)))
67     {
68         pr.showpr();
69     }
70     fp.close();
71     
return 0;
72 }

73 int
dispsp()
74 {
75     
int flag=0,n;
76     cout<<
"Enter the product number: "<<endl;
77     cin>>n;
78     fp.open(
"SMBS.dat",ios::in|ios::out);
79     
while(fp.read((char*)&pr,sizeof(product)))
80     {
81         
if(pr.retprno()==n)
82         {
83             pr.showpr();
84             flag=
1;
85         }
86     }
87     fp.close();
88     
if(flag==0)
89     {
90         cout<<
"Record does not exist"<<endl;
91     }
92     
return 0;
93 }

94 int
modifypr()
95 {
96     
int no,found=0;
97     system(
"cls");
98     cout<<
"Enter the product number:"<<endl;
99     cin>>no;
100     fp.open(
"SMBS.dat",ios::in|ios::out);
101     
while(fp.read((char*)&pr,sizeof(product))&&found==0)
102     {
103        
if(pr.retprno()==no)
104        {
105            pr.showpr();
106            cout<<
"Enter the new details of the product:"<<endl;
107            pr.createpr();
108            
int long long pos=-1*sizeof(pr);
109            fp.seekp(pos,ios::cur);
110            fp.write((
char*)&pr,sizeof(product));
111            cout<<
"The details of the product has been modified"<<endl;
112            found=
1;
113
114        }
115     }
116     fp.close();
117     
if(found==0)
118     {
119         cout<<
"Record not found"<<endl;
120     }
121     
return 0;
122 }

123 int
deletepr()
124 {
125     
int num;
126     system(
"cls");
127     cout<<
"Enter the product number of the product you want to delete"<<endl;
128     cin>>num;
129     fp.open(
"SMBS.dat",ios::in|ios::out);
130     fstream fp2;
131     fp2.open(
"Temporary.dat",ios::out);
132     fp.seekg(
0,ios::beg);
133     
while(fp.read((char*)&pr,sizeof(product)))
134     {
135         
if(pr.retprno()!=num)
136         {
137             fp2.write((
char*)&pr,sizeof(product));
138         }
139     }
140     fp2.close();
141     fp.close();
142     
remove("SMBS.dat");
143     rename(
"Temporary.dat","SMBS.dat");
144     cout<<
"The record of the product has been deleted"<<endl;
145     
return 0;
146 }

147 int
menu()
148 {
149     system(
"cls");
150     fp.open(
"SMBS.dat",ios::in);
151     
if(!fp)
152     {
153         cout<<
"Error:The file cannot be opened, head over to the Admin menu to create a new file."<<endl;
154         exit(
0);
155     }
156     
else
157     cout<<
"Product Menu:"<<endl;
158     cout<<
"---------------------------------------------"<<endl;
159     cout<<
"Product number:\t\tName:\t\tPrice:"<<endl;
160     cout<<
"---------------------------------------------"<<endl;
161     
while(fp.read((char*)&pr,sizeof(product)))
162     {
163         cout<<
"\t"<<pr.retprno()<<"\t\t"<<pr.retname()<<"\t\t"<<pr.retprice()<<endl;
164     }
165     fp.close();
166     
return 0;
167 }

168 int
placeorder()
169 {
170     system(
"cls");
171     
int order[50],quan[50],c=0;
172     
float amt,damt,total=0;
173     
char ch='Y';
174     menu();
175     cout<<
"\n\n\n\n---------------------------------------------";
176     cout<<
"\n-Place your order-"<<endl;
177     cout<<
"---------------------------------------------"<<endl;
178     
do
179     {
180         cout<<
"Enter the product number:"<<endl;
181         cin>>order[c];
182         cout<<
"Enter the quantity:"<<endl;
183         cin>>quan[c];
184         c++;
185         cout<<
"Do want to order another product? (Y/N):"<<endl;
186         cin>>ch;
187     }
while(ch=='y'||ch=='Y');
188     cout<<
"Invoice:"<<endl;
189     cout<<
"Product number\tProduct Name\tQuantity\tPrice\tAmount\tAmount after discount"<<endl;
190     
for(int x=0;x<=c;x++)
191     {
192         fp.open(
"SMBS.dat",ios::in);
193         fp.read((
char*)&pr,sizeof(product));
194         
while(!fp.eof())
195         {
196             
if(pr.retprno()==order[x])
197             {
198                 amt=pr.retprice()*quan[x];
199                 damt=amt-(amt*pr.retdis()/
100);
200                 cout<<
"\n"<<"\t"<<order[x]<<"\t"<<pr.retname()<<"\t\t"<<quan[x]<<"\t\t"<<pr.retprice()<<"\t"<<amt<<"\t\t"<<damt;
201                 total=total+damt;
202             }
203             fp.read((
char*)&pr,sizeof(product));
204         }
205         fp.close();
206     }
207     cout<<
"\n\n\t\t\t\t\tTotal:"<<total;
208     
return 0;
209 }

210 int
into()
211 {
212     cout<<
"-----Super Market Billing System Version 2-----"<<endl;
213     cout<<
"\nMade by: code-projects.org"<<endl;
214
215     
return 0;
216 }

217 int
admin()
218 {
219     system(
"cls");
220     
char ch2;
221     cout<<
"Administration menu:"<<endl;
222     cout<<
"1.Create a product."<<endl;
223     
//cout<<"2.Display all products."<<endl;
224     
//cout<<"3.Query- Display a specific product."<<endl;
225     cout<<
"2.Modify a product"<<endl;
226     cout<<
"3.Delete a product."<<endl;
227     cout<<
"4.View product menu."<<endl;
228     cout<<
"5.Back to main menu()."<<endl;
229     cout<<
"Enter your choice:"<<endl;
230     ch2=getche();
231     
switch(ch2)
232     {
233     
case '1':
234         {
235             writepr();
236             
break;
237         }
238     
//case '2':
239         {
240             disp();
241             
break;
242         }
243     
//case '3':
244         {
245             system(
"cls");
246             dispsp();
247             
break;
248         }
249     
case '2':
250         {
251            modifypr();
252            
break;
253         }
254     
case '3':
255         {
256             deletepr();
257             
break;
258         }
259     
case '4':
260         {
261             menu();
262             getch();
263         }
264     
case '5':
265         {
266             
break;
267         }
268         
default: cout<<"\a";admin();
269     }
270     
return 0;
271 }

272 int
main()
273 {
274     
char ch;
275     
into();
276     
do
277     {
278         cout<<
"\n\nWelcome to The Super Market Billing System Application"<<endl;
279         cout<<
"Main Menu:"<<endl;
280         cout<<
"1.Customer"<<endl;
281         cout<<
"2.Administrator"<<endl;
282         cout<<
"3.Exit"<<endl;
283         cout<<
"Enter your choice:"<<endl;
284         ch=getche();
285         
switch(ch)
286         {
287         
case '1':
288             {
289                 placeorder();
290                 getch();
291                 
break;
292             }
293         
case '2':
294             {
295                 admin();
296                 
break;
297             }
298         
case '3':
299             {
300                 exit(
0);
301             }
302             
default:cout<<"\a";
303         }
304         system(
"cls");
305     }
while(ch!=3);
306     
return 0;
307 }


Gõ tìm kiếm nhanh...